import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import router from './router'
import store from './store';
import Cookie from 'js-cookie'
Vue.config.productionTip = false
Vue.use(ElementUI);

// 添加全局导航守卫
router.beforeEach((to, from, next) => {
  // 判断token是否存在
  const token = Cookie.get('token')
  // token不存在，跳转到登录页面
  if (to.path == '/login') return next();
  if (to.path == '/register') return next();
  if (!token) return next('/login')
  next()
})


new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')
